import Vue from 'vue'
import store from '@/store'
import { cache } from './jdk'

export const storeToken = (token = '') => {
  if (!store.state.token) {
    cache('token', token)
    store.commit('setState', { token })
    store.dispatch('getUserInfo')
    if (Vue.tokenReadyCallback) Vue.tokenReadyCallback(token)
  }
  return true
}

export const clearToken = () => {
  cache('token', null)
  store.commit('setState', { token: '', userInfo: {} })
  return true
}
